﻿@using Resources
@using QAS.Nekorama.Common
@using QAS.Nekorama.Models
@using PagedList.Mvc
@model UserModel
@{
    ViewBag.Title = QAS_Nekorama.PERSONAL_PAGE;
}
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />

<script type="text/javascript">
    $(".ban").live("click", function(e) {
        e.preventDefault();
        var url = "/User/BanUser/" + '?userId=@Model.Users.UserID';
        $("#dialog-confirm").dialog({
            autoOpen: false,
            resizable: false,
            height: 170,
            width: 350,
            show: { effect: 'drop', direction: "up" },
            modal: true,
            draggable: true,
            buttons: {
                "OK": function() {
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: null,
                        dataType: 'json',
                        cash: false,
                        success:location.reload(false)
                    });
                    $(this).dialog("close");

                },
                "Cancel": function() {
                    $(this).dialog("close");

                }
            }
        });

        $("#dialog-confirm").dialog('open');
        return false;
    });
</script>

<div id="dialog" title="Basic dialog" style="display: none">
    <p style="line-height: normal;">@Messages.BAN_CONFIRM</p>
</div>

<div id="primary">
    <div id="primary-1">
        <!--ERROR LIST-->
                @if (TempData["error"] != null)
                {       
        <div class="error-list">
            <ul>
                <li>@TempData["error"]</li>
            </ul>
            </div>
            <!--end error-list-->
                    }

        @if (Model.Users.BanDuration > 0)
        {
            <h1 style="color: red">@QAS_Nekorama.BANNED_USER @Model.Users.BanDuration @QAS_Nekorama.BAN_DURATION</h1>
        }
    </div>
    
    <!--end primary-1-->

    <div id="primary-2">
        <div id="user-details">
            <div class="user-profile">
                <div class="user-avatar">
                    <img src="@Html.Raw("/Images/Avatars/" + Model.Users.Avatar)" alt="nekorama profile picture" />
                    <h1>@Model.Users.DisplayName</h1>
                    <p style="font-size: 25px;">@Model.Users.Reputation</p>
                    <p>@QAS_Nekorama.REP</p>
                </div>
                <!--end user-avatar-->

                <div class="user-data">
                    <h2>@Model.Users.FullName</h2>
                    <h3>@QAS_Nekorama.LOCATION</h3>
                    <p>@Model.Users.Location</p>
                    <h3>@QAS_Nekorama.BIRTHDAY</h3>
                    <p>@String.Format("{0:yyy-MM-dd}", Model.Users.DateOfBirth)</p>
                    <h3>@QAS_Nekorama.SINCE</h3>
                    <p>@String.Format("{0:yyy-MM-dd}", Model.Users.CreateDate)</p>
                </div>
                <!--end user-data-->

                <div class="about-me">
                    <h2>@QAS_Nekorama.ABOUT_ME</h2>
                    <p style="min-height: 170px;">@Model.Users.About</p>
                    @if (Model.Users.LastModifiedDate != null)
                    {
                        <p style="color: blue; font-style: italic;">@QAS_Nekorama.LAST_EDIT_TIME: @Model.Users.LastModifiedDate</p>
                    }
                </div>
                <!--end about-me-->
            </div>
            <!--end user-profile-->

            <div class="user-manage">
                @if (WebSecurity.CurrentUserId == Model.Users.UserID && User.Identity.IsAuthenticated && Helper.GetUserInfo(WebSecurity.CurrentUserId).BanDuration == 0)
                {
                    @Html.ActionLink(QAS_Nekorama.EDIT, "Edit", new {userId = @Model.Users.UserID}, new {@class = "edit-user"})
                }

                @if (Model.Users.BanDuration == 0 && Helper.GetReputation(User.Identity.Name) >= (int)@Constants.Privileges.Moderator && WebSecurity.CurrentUserId != Model.Users.UserID &&  Helper.GetUserInfo(WebSecurity.CurrentUserId).BanDuration == 0)
                {
                    @Html.ActionLink(QAS_Nekorama.BAN, null, null, new {userId = @Model.Users.UserID}, new {@class = "ban"})
                }
            </div>
            <!--end user-manage-->

            <div class="summary">
                <h1>@QAS_Nekorama.HISTORY</h1>
                <br />
                <!--POSTED ANSWER LIST-->
                <table style="vertical-align: top;">
                    <tr>
                        <td>
                            <!--POSTED QUESTION LIST-->
                            <div class="posted">
                                <h2>@QAS_Nekorama.QUESTIONS</h2>
                                <ul class="post-link">
                                    @foreach (Question q in Model.Questions)
                                    {
                                        <li>
                                            <p>@q.ViewCount</p>
                                            @Html.ActionLink(Helper.Html2Text(q.Title), "Details", "Question", new {id = q.QuestionID}, null)</li>
                                    }
                                </ul>
                                <!--end post-link-->
                                <ul>
                                    @Html.PagedListPager(Model.Questions, questionPage => Url.Action("Details", new {userid = Model.Users.UserID, questionPage}), 
                                        new PagedListRenderOptions {LinkToFirstPageFormat = String.Format("««"), LinkToPreviousPageFormat = String.Format("«"), 
                                        LinkToNextPageFormat = String.Format("»"), LinkToLastPageFormat = String.Format("»»"), MaximumPageNumbersToDisplay = 5, 
                                        DisplayEllipsesWhenNotShowingAllPageNumbers = false})
                                </ul>
                            </div>
                            <!--end posted-->
                            <!--END POSTED QUESTION LIST-->
                        </td>
                        <td>
                            <div class="posted">
                                <h2>@QAS_Nekorama.ANSWERS</h2>
                                <ul class="post-link">
                                    @foreach (Answer a
                                        in Model.Answers)
                                    {
                                        <li>@Html.ActionLink(Helper.Html2Text(a.Content).Substring(0, 29) + "...", "Details", "Question", new {id = a.QuestionID}, null)</li>
                                    }
                                </ul>
                                <!--end post-link-->
                                <ul>
                                    @Html.PagedListPager(Model.Answers, answerPage => Url.Action("Details", new {userid = Model.Users.UserID, answerPage}), 
                                    new PagedListRenderOptions {LinkToFirstPageFormat = String.Format("««"), LinkToPreviousPageFormat = String.Format("«"), 
                                    LinkToNextPageFormat = String.Format("»"), LinkToLastPageFormat = String.Format("»»"), MaximumPageNumbersToDisplay = 5, DisplayEllipsesWhenNotShowingAllPageNumbers = false})
                                </ul>
                            </div>
                            <!--end posted-->
                            <!--END POSTED ANSWER LIST-->
                        </td>
                    </tr>
                </table>
            </div>
            <!--end summary-->
        </div>
        <!--end user-details-->
    </div>
    <!--end primary-2-->

    <div id="primary-3">
    </div>
    <!--end primary-3-->
</div>
<!--end primary-->

<div id="dialog-confirm" style="display: none">
    <p>
        <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
        @Messages.BAN_CONFIRM
    </p>
</div>
<!--end dialog-confirm-->